package com.xiangxiao.rpan.data.controller;

import com.xiangxiao.rpan.data.model.Greetings;
import com.xiangxiao.rpan.data.service.GreetingsService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther xiangxiao
 * @email 573768011@qq.com
 * @data 2024/5/30 17:10
 */
@RestController
public class GreetingsController {
  private final GreetingsService greetingsService;

  public GreetingsController(GreetingsService greetingsService) {
    this.greetingsService = greetingsService;
  }

  // 测试url: http://localhost:8060/greetings?message=hello
  @GetMapping("/greetings")
  @ResponseStatus(HttpStatus.ACCEPTED)
  public void greetings(@RequestParam("message") String message) {
    Greetings greetings = Greetings.builder()
        .message(message)
        .timestamp(System.currentTimeMillis())
        .build();

    greetingsService.sendGreeting(greetings);
  }
}
